#define _CRT_SECURE_NO_WARNINGS 
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>


class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int len = 0, n = nums.size();
        for (int i = 0; i < n - 1; i++)
        {
            int left = i;
            static int right = 0
                int sum = 0;
            while (right < n)
            {
                sum += nums[left] + nums[right++];
                if (sum < target)
                {
                    sum += nums[right++];
                }
                else
                {
                    len = right - left;
                }
            }

        }
        return len;
    }
};


class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int len = INT_MAX, n = nums.size();
        int sum = 0;
        int left = 0;
        for (int right = 0; right < n; right++)
        {
            sum += nums[right];
            while (sum >= target)
            {
                len = min(len, right - left + 1);
                sum -= nums[left++];
            }
        }
        return len == INT_MAX ? 0 : len;
    }
};



////////////////////////////////////////////////////////////
class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int hash[128] = { 0 };
        int n = s.size(), ret = 0;
        int left = 0, right = 0;
        while (right < n)
        {
            hash[s[right]]++;
            while (hash[s[right]] > 1)
                hash[s[left++]]--;
            ret = max(ret, right - left + 1);
            right++;
        }
        return ret;
    }
};